using SqlSugar;
using System.Reflection;

namespace xjjxmm.infrastructure.repository.impl.sugar;

public class SqlHelper

{
	public static string GetTableName<T>()
	{
		return typeof(T).GetCustomAttribute<SugarTable>()?.TableName ?? typeof(T).Name;
	}

	public static void AutoCreateTable<T>(ISqlSugarClient sqlSugarClient)
	{
		if (!sqlSugarClient.DbMaintenance.IsAnyTable(GetTableName<T>(), false))
		{
			sqlSugarClient.CodeFirst.InitTables(typeof(T));
		}
	}

}